function slice(arr, start, end) {
  if (arr.length === 0) {
    return [];
  }

  start = start || 0;

  if (start >= arr.length) {
    return [];
  }

  end = end || arr.length;
  if (end <= start) {
    end = arr.length;
  }

  let result = [];

  for (let i = 0; i < arr.length; i++) {
    if (i >= start && i < end) {
      result.push(arr[i]);
    }
  }
  return result;
}
